package com.xl.factoryMethodPattern;

public class Client {
    public static void main(String[] args) {
        //方式1：直接使用具体工厂
        LoggerFactory factory = new FileLoggerFactory();
        Logger logger = factory.createLogger();
        logger.log("这是一个测试消息");

        //方式2：使用工厂的便捷方法
        factory.log("直接使用工厂记录日志");

        //方式3：根据配置动态选择工厂
        LoggerFactory configuredFactory = getLoggerFactoryBasedOnConfiguration("file");
        configuredFactory.log("使用配置选择工厂记录日志");
    }

    private static LoggerFactory getLoggerFactoryBasedOnConfiguration(String logType) {
        return switch (logType) {
            case "file" -> new FileLoggerFactory();
            case "database" -> new DatabaseLoggerFactory();
            default -> throw new IllegalArgumentException("Unknown logger type: " + logType);
        };
    }
}
